var express = require('express');
var router = express.Router();
var async = require('async');
var db = require('./../../utils/db.js');


/* GET users listing. */
router.get('/', function (req, res, next) {
    res.redirect('/daily/weekPlan/list')
});

router.get('/list', function (req, res, next) {
    res.render('daily/weekPlan/weeklyplans');
});

router.get('/entry', function (req, res, next) {
    let projectSql = 'select id, project_name from project_base';
    let userSql = 'select id,person_name from base_user';

    async.series([
        function (callback) {
            db.query(projectSql, function (err, rows) {
                callback(err, rows);
            });
        },
        function (callback) {
            db.query(userSql, function (err, rows) {
                callback(err, rows);
            });
        }
    ], function (err, values) {
        if (values && values.length > 1) {
            res.render('daily/weekPlan/weeklyplanentry', {
                projectList: values[0],
                userList: values[1]
            });
        } else {
            console.error(err);
            res.render('daily/weekPlan/weeklyplanentry');
        }

    });


});

router.post('/savePlanList', function (req, res, next) {
    console.log(req.body);
    res.json({
        errcode: 1,
        message: '保存失败'
    });
});


module.exports = router;